#ifndef MYQUSTOMPLOT_H
#define MYQUSTOMPLOT_H
#include "MyCore/qcustomplot.h"
#include <QEvent>
#include <QMouseEvent>

#define XAXIS_W 100 //X轴长度
class MyQCustomPlot : public QCustomPlot
{
public:
    MyQCustomPlot(QWidget *parent = nullptr);
    ~MyQCustomPlot();

public:
    void setChart(const double &starY, const double &endY); // 绘制柱状图(传入Y轴范围)
    void setData(const QVector<double> &fossilData);        //设置Y值
    void showData(const QPoint &localPos);                      //tooltip展示


private:
    //bool eventFilter(QObject *obj, QEvent *event)override;  //事件过滤器（鼠标悬停）
    void mousePressEvent(QMouseEvent *event)override;
    void mouseReleaseEvent(QMouseEvent *event) override;
private:
    QString getDataByPos(const QPoint& cursorPos);          //根据坐标获取其的数据

private:
  QCPBars *bar_;                // 用于绘制柱状图
  QVector<double> x_;           // x轴
  QVector<double> y_;           // y轴数据


  QCPAxis *xAxis_;              // x轴格式
  QCPAxis *yAxis_;              // y轴格式
};

#endif // MYQUSTOMPLOT_H
